package com.example.shushiyunsst.fragment.main.home.child.miner.sub

import android.os.Bundle
import android.view.View
import com.example.library_common.adapter.JssBaseViewHolder
import com.example.library_common.album.utils.Utils
import com.example.library_common.base.SimpleListFragment
import com.example.library_common.bean.CommonBean
import com.example.library_common.utils.PixUtils
import com.example.shushiyunsst.R
import com.example.shushiyunsst.fragment.main.home.child.miner.bean.StartTransferFormBean
import ikidou.reflect.TypeBuilder
import java.lang.reflect.Type

/**
 * 制作星树（表单）
 * */
class MakeTreeFormFragment : SimpleListFragment<StartTransferFormBean>() {

    companion object {
        fun newInstance(): MakeTreeFormFragment {
            val args = Bundle()
            val fragment = MakeTreeFormFragment()
            fragment.arguments = args
            return fragment
        }
    }

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        delayedTime=0
        mSuperBackPressedSupport = false
        isEnableLoadMore=false
        isAddDividerItemDecoration=false
        isInitialRefresh=false
        isAlwaysRefresh=false
    }

    override fun initView(view: View) {
        super.initView(view)
        view.setBackgroundResource(R.drawable.bg_rect)

        mHeader.removeAllViews()
        addHeader(R.layout.start_transfer_form_item_title_layout)

        mRecyclerView.overScrollMode=View.OVER_SCROLL_NEVER
    }

    override fun getItemLayout()= R.layout.start_transfer_form_item_layout

    override fun convertItem(helper: JssBaseViewHolder?, item: StartTransferFormBean?) {
        helper?.setText(R.id.energy_start_making_type,item?.makingType)
            ?.setText(R.id.energy_start_make,item?.make.toString())
            ?.setText(R.id.energy_start_store,item?.count.toString())
    }

    override fun getListType(): Type {
        return TypeBuilder.newInstance(CommonBean::class.java)
            .beginSubType(List::class.java)
            .addTypeParam(StartTransferFormBean::class.java).endSubType().build()
    }

    override fun netRequest() {
        val jsonFromRaw = Utils.getJsonFromRaw(_mActivity, R.raw.start_transfer_form)
        parseDate(jsonFromRaw)

        mHeader.measure(0,0)
        mRecyclerView.measure(0,0)
        val layoutParams = rootView.layoutParams
        layoutParams.height=mHeader.height+mRecyclerView.measuredHeight+PixUtils.dp2px(14)
        rootView.layoutParams=layoutParams
    }
}